/*********************************************************/
/*
    functor for dynamic binding
    TEMPLATE_ARGS = 
    FUNCTION_ARGS = 
    DELEGATE_PARA = 
*/
template<typename Ret , typename BindType, typename ClassType>
class worker<Ret(), BindType, ClassType>
{
public:
    typedef acapella::delegate::functor
        <Ret(), BindType, ClassType> 
        functor_type;
    typedef acapella::delegate::delegate
        <Ret(), BindType, ClassType> 
        delegate_type;
    typedef acapella::shared_ptr<delegate_type> delegate_pointer_type;
    typedef acapella::shared_ptr<Task> task_pointer_type;

    worker()
    {
    }

    worker(functor_type _functor)
        :functor_(_functor)
    {
    }

    virtual ~worker()
    {
    }

    worker(const worker& _worker)
        :functor_(_worker.functor_)
    {
    }

    worker& operator= (const worker& _worker)
    {
        if (this == &_worker)
        {
            return *this;
        }
        functor_ = _worker.functor_;
        return *this;
    }

    Ret SyncCall()
    {
        delegate_pointer_type pDelegate(
            new delegate_type(functor_ ));

        return SyncDelegate(pDelegate);
    }

    void AsynCall()
    {
        delegate_pointer_type pDelegate(
            new delegate_type(functor_ ));
        
        AsynDelegate(pDelegate);
        return;
    }

    Ret SyncDelegate(delegate_pointer_type pDelegate)
    {
        Ret returnVal;

        task_pointer_type pTask = _MakeSyncTask(pDelegate, returnVal);
        
        // schedule the task
        Schedule(pTask);

        return returnVal;        
    }

    void AsynDelegate(delegate_pointer_type pDelegate)
    {
        task_pointer_type pTask = _MakeAsynTask(pDelegate);

        // schedule the task
        Schedule(pTask);

        return;
    }

    void Schedule(task_pointer_type pTask)
    {
        _Schedule(pTask);

        pTask->wait();
    }

    void SetFunctor(const functor_type& _functor)
    {
        functor_ = _functor;
    }

    const functor_type& GetFunctor()
    {
        return functor_;
    }

protected:

    virtual task_pointer_type _MakeSyncTask(delegate_pointer_type pDelegate, Ret& returnRef)
    {
        return task_pointer_type(new SyncTask<
                                 delegate_type, 
                                 acapella::synchronize::_default_::semaphore
                                 >(pDelegate, returnRef));
    }

    virtual task_pointer_type _MakeAsynTask(delegate_pointer_type pDelegate)
    {
        return task_pointer_type(new AsynTask<delegate_type>(pDelegate));
    }

    virtual void _Schedule(task_pointer_type pTask) = 0;

    functor_type functor_;
};
/*********************************************************/
/*
    functor for dynamic binding
    TEMPLATE_ARGS = , typename T0
    FUNCTION_ARGS = T0 t0
    DELEGATE_PARA = , t0
*/
template<typename Ret , typename T0, typename BindType, typename ClassType>
class worker<Ret(T0 t0), BindType, ClassType>
{
public:
    typedef acapella::delegate::functor
        <Ret(T0 t0), BindType, ClassType> 
        functor_type;
    typedef acapella::delegate::delegate
        <Ret(T0 t0), BindType, ClassType> 
        delegate_type;
    typedef acapella::shared_ptr<delegate_type> delegate_pointer_type;
    typedef acapella::shared_ptr<Task> task_pointer_type;

    worker()
    {
    }

    worker(functor_type _functor)
        :functor_(_functor)
    {
    }

    virtual ~worker()
    {
    }

    worker(const worker& _worker)
        :functor_(_worker.functor_)
    {
    }

    worker& operator= (const worker& _worker)
    {
        if (this == &_worker)
        {
            return *this;
        }
        functor_ = _worker.functor_;
        return *this;
    }

    Ret SyncCall(T0 t0)
    {
        delegate_pointer_type pDelegate(
            new delegate_type(functor_ , t0));

        return SyncDelegate(pDelegate);
    }

    void AsynCall(T0 t0)
    {
        delegate_pointer_type pDelegate(
            new delegate_type(functor_ , t0));
        
        AsynDelegate(pDelegate);
        return;
    }

    Ret SyncDelegate(delegate_pointer_type pDelegate)
    {
        Ret returnVal;

        task_pointer_type pTask = _MakeSyncTask(pDelegate, returnVal);
        
        // schedule the task
        Schedule(pTask);

        return returnVal;        
    }

    void AsynDelegate(delegate_pointer_type pDelegate)
    {
        task_pointer_type pTask = _MakeAsynTask(pDelegate);

        // schedule the task
        Schedule(pTask);

        return;
    }

    void Schedule(task_pointer_type pTask)
    {
        _Schedule(pTask);

        pTask->wait();
    }

    void SetFunctor(const functor_type& _functor)
    {
        functor_ = _functor;
    }

    const functor_type& GetFunctor()
    {
        return functor_;
    }

protected:

    virtual task_pointer_type _MakeSyncTask(delegate_pointer_type pDelegate, Ret& returnRef)
    {
        return task_pointer_type(new SyncTask<
                                 delegate_type, 
                                 acapella::synchronize::_default_::semaphore
                                 >(pDelegate, returnRef));
    }

    virtual task_pointer_type _MakeAsynTask(delegate_pointer_type pDelegate)
    {
        return task_pointer_type(new AsynTask<delegate_type>(pDelegate));
    }

    virtual void _Schedule(task_pointer_type pTask) = 0;

    functor_type functor_;
};
/*********************************************************/
/*
    functor for dynamic binding
    TEMPLATE_ARGS = , typename T0, typename T1
    FUNCTION_ARGS = T0 t0, T1 t1
    DELEGATE_PARA = , t0, t1
*/
template<typename Ret , typename T0, typename T1, typename BindType, typename ClassType>
class worker<Ret(T0 t0, T1 t1), BindType, ClassType>
{
public:
    typedef acapella::delegate::functor
        <Ret(T0 t0, T1 t1), BindType, ClassType> 
        functor_type;
    typedef acapella::delegate::delegate
        <Ret(T0 t0, T1 t1), BindType, ClassType> 
        delegate_type;
    typedef acapella::shared_ptr<delegate_type> delegate_pointer_type;
    typedef acapella::shared_ptr<Task> task_pointer_type;

    worker()
    {
    }

    worker(functor_type _functor)
        :functor_(_functor)
    {
    }

    virtual ~worker()
    {
    }

    worker(const worker& _worker)
        :functor_(_worker.functor_)
    {
    }

    worker& operator= (const worker& _worker)
    {
        if (this == &_worker)
        {
            return *this;
        }
        functor_ = _worker.functor_;
        return *this;
    }

    Ret SyncCall(T0 t0, T1 t1)
    {
        delegate_pointer_type pDelegate(
            new delegate_type(functor_ , t0, t1));

        return SyncDelegate(pDelegate);
    }

    void AsynCall(T0 t0, T1 t1)
    {
        delegate_pointer_type pDelegate(
            new delegate_type(functor_ , t0, t1));
        
        AsynDelegate(pDelegate);
        return;
    }

    Ret SyncDelegate(delegate_pointer_type pDelegate)
    {
        Ret returnVal;

        task_pointer_type pTask = _MakeSyncTask(pDelegate, returnVal);
        
        // schedule the task
        Schedule(pTask);

        return returnVal;        
    }

    void AsynDelegate(delegate_pointer_type pDelegate)
    {
        task_pointer_type pTask = _MakeAsynTask(pDelegate);

        // schedule the task
        Schedule(pTask);

        return;
    }

    void Schedule(task_pointer_type pTask)
    {
        _Schedule(pTask);

        pTask->wait();
    }

    void SetFunctor(const functor_type& _functor)
    {
        functor_ = _functor;
    }

    const functor_type& GetFunctor()
    {
        return functor_;
    }

protected:

    virtual task_pointer_type _MakeSyncTask(delegate_pointer_type pDelegate, Ret& returnRef)
    {
        return task_pointer_type(new SyncTask<
                                 delegate_type, 
                                 acapella::synchronize::_default_::semaphore
                                 >(pDelegate, returnRef));
    }

    virtual task_pointer_type _MakeAsynTask(delegate_pointer_type pDelegate)
    {
        return task_pointer_type(new AsynTask<delegate_type>(pDelegate));
    }

    virtual void _Schedule(task_pointer_type pTask) = 0;

    functor_type functor_;
};
/*********************************************************/
/*
    functor for dynamic binding
    TEMPLATE_ARGS = , typename T0, typename T1, typename T2
    FUNCTION_ARGS = T0 t0, T1 t1, T2 t2
    DELEGATE_PARA = , t0, t1, t2
*/
template<typename Ret , typename T0, typename T1, typename T2, typename BindType, typename ClassType>
class worker<Ret(T0 t0, T1 t1, T2 t2), BindType, ClassType>
{
public:
    typedef acapella::delegate::functor
        <Ret(T0 t0, T1 t1, T2 t2), BindType, ClassType> 
        functor_type;
    typedef acapella::delegate::delegate
        <Ret(T0 t0, T1 t1, T2 t2), BindType, ClassType> 
        delegate_type;
    typedef acapella::shared_ptr<delegate_type> delegate_pointer_type;
    typedef acapella::shared_ptr<Task> task_pointer_type;

    worker()
    {
    }

    worker(functor_type _functor)
        :functor_(_functor)
    {
    }

    virtual ~worker()
    {
    }

    worker(const worker& _worker)
        :functor_(_worker.functor_)
    {
    }

    worker& operator= (const worker& _worker)
    {
        if (this == &_worker)
        {
            return *this;
        }
        functor_ = _worker.functor_;
        return *this;
    }

    Ret SyncCall(T0 t0, T1 t1, T2 t2)
    {
        delegate_pointer_type pDelegate(
            new delegate_type(functor_ , t0, t1, t2));

        return SyncDelegate(pDelegate);
    }

    void AsynCall(T0 t0, T1 t1, T2 t2)
    {
        delegate_pointer_type pDelegate(
            new delegate_type(functor_ , t0, t1, t2));
        
        AsynDelegate(pDelegate);
        return;
    }

    Ret SyncDelegate(delegate_pointer_type pDelegate)
    {
        Ret returnVal;

        task_pointer_type pTask = _MakeSyncTask(pDelegate, returnVal);
        
        // schedule the task
        Schedule(pTask);

        return returnVal;        
    }

    void AsynDelegate(delegate_pointer_type pDelegate)
    {
        task_pointer_type pTask = _MakeAsynTask(pDelegate);

        // schedule the task
        Schedule(pTask);

        return;
    }

    void Schedule(task_pointer_type pTask)
    {
        _Schedule(pTask);

        pTask->wait();
    }

    void SetFunctor(const functor_type& _functor)
    {
        functor_ = _functor;
    }

    const functor_type& GetFunctor()
    {
        return functor_;
    }

protected:

    virtual task_pointer_type _MakeSyncTask(delegate_pointer_type pDelegate, Ret& returnRef)
    {
        return task_pointer_type(new SyncTask<
                                 delegate_type, 
                                 acapella::synchronize::_default_::semaphore
                                 >(pDelegate, returnRef));
    }

    virtual task_pointer_type _MakeAsynTask(delegate_pointer_type pDelegate)
    {
        return task_pointer_type(new AsynTask<delegate_type>(pDelegate));
    }

    virtual void _Schedule(task_pointer_type pTask) = 0;

    functor_type functor_;
};
/*********************************************************/
/*
    functor for dynamic binding
    TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3
    FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3
    DELEGATE_PARA = , t0, t1, t2, t3
*/
template<typename Ret , typename T0, typename T1, typename T2, typename T3, typename BindType, typename ClassType>
class worker<Ret(T0 t0, T1 t1, T2 t2, T3 t3), BindType, ClassType>
{
public:
    typedef acapella::delegate::functor
        <Ret(T0 t0, T1 t1, T2 t2, T3 t3), BindType, ClassType> 
        functor_type;
    typedef acapella::delegate::delegate
        <Ret(T0 t0, T1 t1, T2 t2, T3 t3), BindType, ClassType> 
        delegate_type;
    typedef acapella::shared_ptr<delegate_type> delegate_pointer_type;
    typedef acapella::shared_ptr<Task> task_pointer_type;

    worker()
    {
    }

    worker(functor_type _functor)
        :functor_(_functor)
    {
    }

    virtual ~worker()
    {
    }

    worker(const worker& _worker)
        :functor_(_worker.functor_)
    {
    }

    worker& operator= (const worker& _worker)
    {
        if (this == &_worker)
        {
            return *this;
        }
        functor_ = _worker.functor_;
        return *this;
    }

    Ret SyncCall(T0 t0, T1 t1, T2 t2, T3 t3)
    {
        delegate_pointer_type pDelegate(
            new delegate_type(functor_ , t0, t1, t2, t3));

        return SyncDelegate(pDelegate);
    }

    void AsynCall(T0 t0, T1 t1, T2 t2, T3 t3)
    {
        delegate_pointer_type pDelegate(
            new delegate_type(functor_ , t0, t1, t2, t3));
        
        AsynDelegate(pDelegate);
        return;
    }

    Ret SyncDelegate(delegate_pointer_type pDelegate)
    {
        Ret returnVal;

        task_pointer_type pTask = _MakeSyncTask(pDelegate, returnVal);
        
        // schedule the task
        Schedule(pTask);

        return returnVal;        
    }

    void AsynDelegate(delegate_pointer_type pDelegate)
    {
        task_pointer_type pTask = _MakeAsynTask(pDelegate);

        // schedule the task
        Schedule(pTask);

        return;
    }

    void Schedule(task_pointer_type pTask)
    {
        _Schedule(pTask);

        pTask->wait();
    }

    void SetFunctor(const functor_type& _functor)
    {
        functor_ = _functor;
    }

    const functor_type& GetFunctor()
    {
        return functor_;
    }

protected:

    virtual task_pointer_type _MakeSyncTask(delegate_pointer_type pDelegate, Ret& returnRef)
    {
        return task_pointer_type(new SyncTask<
                                 delegate_type, 
                                 acapella::synchronize::_default_::semaphore
                                 >(pDelegate, returnRef));
    }

    virtual task_pointer_type _MakeAsynTask(delegate_pointer_type pDelegate)
    {
        return task_pointer_type(new AsynTask<delegate_type>(pDelegate));
    }

    virtual void _Schedule(task_pointer_type pTask) = 0;

    functor_type functor_;
};
/*********************************************************/
/*
    functor for dynamic binding
    TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4
    FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4
    DELEGATE_PARA = , t0, t1, t2, t3, t4
*/
template<typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4, typename BindType, typename ClassType>
class worker<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4), BindType, ClassType>
{
public:
    typedef acapella::delegate::functor
        <Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4), BindType, ClassType> 
        functor_type;
    typedef acapella::delegate::delegate
        <Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4), BindType, ClassType> 
        delegate_type;
    typedef acapella::shared_ptr<delegate_type> delegate_pointer_type;
    typedef acapella::shared_ptr<Task> task_pointer_type;

    worker()
    {
    }

    worker(functor_type _functor)
        :functor_(_functor)
    {
    }

    virtual ~worker()
    {
    }

    worker(const worker& _worker)
        :functor_(_worker.functor_)
    {
    }

    worker& operator= (const worker& _worker)
    {
        if (this == &_worker)
        {
            return *this;
        }
        functor_ = _worker.functor_;
        return *this;
    }

    Ret SyncCall(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4)
    {
        delegate_pointer_type pDelegate(
            new delegate_type(functor_ , t0, t1, t2, t3, t4));

        return SyncDelegate(pDelegate);
    }

    void AsynCall(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4)
    {
        delegate_pointer_type pDelegate(
            new delegate_type(functor_ , t0, t1, t2, t3, t4));
        
        AsynDelegate(pDelegate);
        return;
    }

    Ret SyncDelegate(delegate_pointer_type pDelegate)
    {
        Ret returnVal;

        task_pointer_type pTask = _MakeSyncTask(pDelegate, returnVal);
        
        // schedule the task
        Schedule(pTask);

        return returnVal;        
    }

    void AsynDelegate(delegate_pointer_type pDelegate)
    {
        task_pointer_type pTask = _MakeAsynTask(pDelegate);

        // schedule the task
        Schedule(pTask);

        return;
    }

    void Schedule(task_pointer_type pTask)
    {
        _Schedule(pTask);

        pTask->wait();
    }

    void SetFunctor(const functor_type& _functor)
    {
        functor_ = _functor;
    }

    const functor_type& GetFunctor()
    {
        return functor_;
    }

protected:

    virtual task_pointer_type _MakeSyncTask(delegate_pointer_type pDelegate, Ret& returnRef)
    {
        return task_pointer_type(new SyncTask<
                                 delegate_type, 
                                 acapella::synchronize::_default_::semaphore
                                 >(pDelegate, returnRef));
    }

    virtual task_pointer_type _MakeAsynTask(delegate_pointer_type pDelegate)
    {
        return task_pointer_type(new AsynTask<delegate_type>(pDelegate));
    }

    virtual void _Schedule(task_pointer_type pTask) = 0;

    functor_type functor_;
};
/*********************************************************/
/*
    functor for dynamic binding
    TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5
    FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5
    DELEGATE_PARA = , t0, t1, t2, t3, t4, t5
*/
template<typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename BindType, typename ClassType>
class worker<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5), BindType, ClassType>
{
public:
    typedef acapella::delegate::functor
        <Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5), BindType, ClassType> 
        functor_type;
    typedef acapella::delegate::delegate
        <Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5), BindType, ClassType> 
        delegate_type;
    typedef acapella::shared_ptr<delegate_type> delegate_pointer_type;
    typedef acapella::shared_ptr<Task> task_pointer_type;

    worker()
    {
    }

    worker(functor_type _functor)
        :functor_(_functor)
    {
    }

    virtual ~worker()
    {
    }

    worker(const worker& _worker)
        :functor_(_worker.functor_)
    {
    }

    worker& operator= (const worker& _worker)
    {
        if (this == &_worker)
        {
            return *this;
        }
        functor_ = _worker.functor_;
        return *this;
    }

    Ret SyncCall(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
    {
        delegate_pointer_type pDelegate(
            new delegate_type(functor_ , t0, t1, t2, t3, t4, t5));

        return SyncDelegate(pDelegate);
    }

    void AsynCall(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
    {
        delegate_pointer_type pDelegate(
            new delegate_type(functor_ , t0, t1, t2, t3, t4, t5));
        
        AsynDelegate(pDelegate);
        return;
    }

    Ret SyncDelegate(delegate_pointer_type pDelegate)
    {
        Ret returnVal;

        task_pointer_type pTask = _MakeSyncTask(pDelegate, returnVal);
        
        // schedule the task
        Schedule(pTask);

        return returnVal;        
    }

    void AsynDelegate(delegate_pointer_type pDelegate)
    {
        task_pointer_type pTask = _MakeAsynTask(pDelegate);

        // schedule the task
        Schedule(pTask);

        return;
    }

    void Schedule(task_pointer_type pTask)
    {
        _Schedule(pTask);

        pTask->wait();
    }

    void SetFunctor(const functor_type& _functor)
    {
        functor_ = _functor;
    }

    const functor_type& GetFunctor()
    {
        return functor_;
    }

protected:

    virtual task_pointer_type _MakeSyncTask(delegate_pointer_type pDelegate, Ret& returnRef)
    {
        return task_pointer_type(new SyncTask<
                                 delegate_type, 
                                 acapella::synchronize::_default_::semaphore
                                 >(pDelegate, returnRef));
    }

    virtual task_pointer_type _MakeAsynTask(delegate_pointer_type pDelegate)
    {
        return task_pointer_type(new AsynTask<delegate_type>(pDelegate));
    }

    virtual void _Schedule(task_pointer_type pTask) = 0;

    functor_type functor_;
};
/*********************************************************/
/*
    functor for dynamic binding
    TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6
    FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6
    DELEGATE_PARA = , t0, t1, t2, t3, t4, t5, t6
*/
template<typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename BindType, typename ClassType>
class worker<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6), BindType, ClassType>
{
public:
    typedef acapella::delegate::functor
        <Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6), BindType, ClassType> 
        functor_type;
    typedef acapella::delegate::delegate
        <Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6), BindType, ClassType> 
        delegate_type;
    typedef acapella::shared_ptr<delegate_type> delegate_pointer_type;
    typedef acapella::shared_ptr<Task> task_pointer_type;

    worker()
    {
    }

    worker(functor_type _functor)
        :functor_(_functor)
    {
    }

    virtual ~worker()
    {
    }

    worker(const worker& _worker)
        :functor_(_worker.functor_)
    {
    }

    worker& operator= (const worker& _worker)
    {
        if (this == &_worker)
        {
            return *this;
        }
        functor_ = _worker.functor_;
        return *this;
    }

    Ret SyncCall(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6)
    {
        delegate_pointer_type pDelegate(
            new delegate_type(functor_ , t0, t1, t2, t3, t4, t5, t6));

        return SyncDelegate(pDelegate);
    }

    void AsynCall(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6)
    {
        delegate_pointer_type pDelegate(
            new delegate_type(functor_ , t0, t1, t2, t3, t4, t5, t6));
        
        AsynDelegate(pDelegate);
        return;
    }

    Ret SyncDelegate(delegate_pointer_type pDelegate)
    {
        Ret returnVal;

        task_pointer_type pTask = _MakeSyncTask(pDelegate, returnVal);
        
        // schedule the task
        Schedule(pTask);

        return returnVal;        
    }

    void AsynDelegate(delegate_pointer_type pDelegate)
    {
        task_pointer_type pTask = _MakeAsynTask(pDelegate);

        // schedule the task
        Schedule(pTask);

        return;
    }

    void Schedule(task_pointer_type pTask)
    {
        _Schedule(pTask);

        pTask->wait();
    }

    void SetFunctor(const functor_type& _functor)
    {
        functor_ = _functor;
    }

    const functor_type& GetFunctor()
    {
        return functor_;
    }

protected:

    virtual task_pointer_type _MakeSyncTask(delegate_pointer_type pDelegate, Ret& returnRef)
    {
        return task_pointer_type(new SyncTask<
                                 delegate_type, 
                                 acapella::synchronize::_default_::semaphore
                                 >(pDelegate, returnRef));
    }

    virtual task_pointer_type _MakeAsynTask(delegate_pointer_type pDelegate)
    {
        return task_pointer_type(new AsynTask<delegate_type>(pDelegate));
    }

    virtual void _Schedule(task_pointer_type pTask) = 0;

    functor_type functor_;
};
/*********************************************************/
/*
    functor for dynamic binding
    TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7
    FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7
    DELEGATE_PARA = , t0, t1, t2, t3, t4, t5, t6, t7
*/
template<typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename BindType, typename ClassType>
class worker<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7), BindType, ClassType>
{
public:
    typedef acapella::delegate::functor
        <Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7), BindType, ClassType> 
        functor_type;
    typedef acapella::delegate::delegate
        <Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7), BindType, ClassType> 
        delegate_type;
    typedef acapella::shared_ptr<delegate_type> delegate_pointer_type;
    typedef acapella::shared_ptr<Task> task_pointer_type;

    worker()
    {
    }

    worker(functor_type _functor)
        :functor_(_functor)
    {
    }

    virtual ~worker()
    {
    }

    worker(const worker& _worker)
        :functor_(_worker.functor_)
    {
    }

    worker& operator= (const worker& _worker)
    {
        if (this == &_worker)
        {
            return *this;
        }
        functor_ = _worker.functor_;
        return *this;
    }

    Ret SyncCall(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7)
    {
        delegate_pointer_type pDelegate(
            new delegate_type(functor_ , t0, t1, t2, t3, t4, t5, t6, t7));

        return SyncDelegate(pDelegate);
    }

    void AsynCall(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7)
    {
        delegate_pointer_type pDelegate(
            new delegate_type(functor_ , t0, t1, t2, t3, t4, t5, t6, t7));
        
        AsynDelegate(pDelegate);
        return;
    }

    Ret SyncDelegate(delegate_pointer_type pDelegate)
    {
        Ret returnVal;

        task_pointer_type pTask = _MakeSyncTask(pDelegate, returnVal);
        
        // schedule the task
        Schedule(pTask);

        return returnVal;        
    }

    void AsynDelegate(delegate_pointer_type pDelegate)
    {
        task_pointer_type pTask = _MakeAsynTask(pDelegate);

        // schedule the task
        Schedule(pTask);

        return;
    }

    void Schedule(task_pointer_type pTask)
    {
        _Schedule(pTask);

        pTask->wait();
    }

    void SetFunctor(const functor_type& _functor)
    {
        functor_ = _functor;
    }

    const functor_type& GetFunctor()
    {
        return functor_;
    }

protected:

    virtual task_pointer_type _MakeSyncTask(delegate_pointer_type pDelegate, Ret& returnRef)
    {
        return task_pointer_type(new SyncTask<
                                 delegate_type, 
                                 acapella::synchronize::_default_::semaphore
                                 >(pDelegate, returnRef));
    }

    virtual task_pointer_type _MakeAsynTask(delegate_pointer_type pDelegate)
    {
        return task_pointer_type(new AsynTask<delegate_type>(pDelegate));
    }

    virtual void _Schedule(task_pointer_type pTask) = 0;

    functor_type functor_;
};
/*********************************************************/
/*
    functor for dynamic binding
    TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8
    FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8
    DELEGATE_PARA = , t0, t1, t2, t3, t4, t5, t6, t7, t8
*/
template<typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename BindType, typename ClassType>
class worker<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8), BindType, ClassType>
{
public:
    typedef acapella::delegate::functor
        <Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8), BindType, ClassType> 
        functor_type;
    typedef acapella::delegate::delegate
        <Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8), BindType, ClassType> 
        delegate_type;
    typedef acapella::shared_ptr<delegate_type> delegate_pointer_type;
    typedef acapella::shared_ptr<Task> task_pointer_type;

    worker()
    {
    }

    worker(functor_type _functor)
        :functor_(_functor)
    {
    }

    virtual ~worker()
    {
    }

    worker(const worker& _worker)
        :functor_(_worker.functor_)
    {
    }

    worker& operator= (const worker& _worker)
    {
        if (this == &_worker)
        {
            return *this;
        }
        functor_ = _worker.functor_;
        return *this;
    }

    Ret SyncCall(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8)
    {
        delegate_pointer_type pDelegate(
            new delegate_type(functor_ , t0, t1, t2, t3, t4, t5, t6, t7, t8));

        return SyncDelegate(pDelegate);
    }

    void AsynCall(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8)
    {
        delegate_pointer_type pDelegate(
            new delegate_type(functor_ , t0, t1, t2, t3, t4, t5, t6, t7, t8));
        
        AsynDelegate(pDelegate);
        return;
    }

    Ret SyncDelegate(delegate_pointer_type pDelegate)
    {
        Ret returnVal;

        task_pointer_type pTask = _MakeSyncTask(pDelegate, returnVal);
        
        // schedule the task
        Schedule(pTask);

        return returnVal;        
    }

    void AsynDelegate(delegate_pointer_type pDelegate)
    {
        task_pointer_type pTask = _MakeAsynTask(pDelegate);

        // schedule the task
        Schedule(pTask);

        return;
    }

    void Schedule(task_pointer_type pTask)
    {
        _Schedule(pTask);

        pTask->wait();
    }

    void SetFunctor(const functor_type& _functor)
    {
        functor_ = _functor;
    }

    const functor_type& GetFunctor()
    {
        return functor_;
    }

protected:

    virtual task_pointer_type _MakeSyncTask(delegate_pointer_type pDelegate, Ret& returnRef)
    {
        return task_pointer_type(new SyncTask<
                                 delegate_type, 
                                 acapella::synchronize::_default_::semaphore
                                 >(pDelegate, returnRef));
    }

    virtual task_pointer_type _MakeAsynTask(delegate_pointer_type pDelegate)
    {
        return task_pointer_type(new AsynTask<delegate_type>(pDelegate));
    }

    virtual void _Schedule(task_pointer_type pTask) = 0;

    functor_type functor_;
};
/*********************************************************/
/*
    functor for dynamic binding
    TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9
    FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9
    DELEGATE_PARA = , t0, t1, t2, t3, t4, t5, t6, t7, t8, t9
*/
template<typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename BindType, typename ClassType>
class worker<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9), BindType, ClassType>
{
public:
    typedef acapella::delegate::functor
        <Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9), BindType, ClassType> 
        functor_type;
    typedef acapella::delegate::delegate
        <Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9), BindType, ClassType> 
        delegate_type;
    typedef acapella::shared_ptr<delegate_type> delegate_pointer_type;
    typedef acapella::shared_ptr<Task> task_pointer_type;

    worker()
    {
    }

    worker(functor_type _functor)
        :functor_(_functor)
    {
    }

    virtual ~worker()
    {
    }

    worker(const worker& _worker)
        :functor_(_worker.functor_)
    {
    }

    worker& operator= (const worker& _worker)
    {
        if (this == &_worker)
        {
            return *this;
        }
        functor_ = _worker.functor_;
        return *this;
    }

    Ret SyncCall(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9)
    {
        delegate_pointer_type pDelegate(
            new delegate_type(functor_ , t0, t1, t2, t3, t4, t5, t6, t7, t8, t9));

        return SyncDelegate(pDelegate);
    }

    void AsynCall(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9)
    {
        delegate_pointer_type pDelegate(
            new delegate_type(functor_ , t0, t1, t2, t3, t4, t5, t6, t7, t8, t9));
        
        AsynDelegate(pDelegate);
        return;
    }

    Ret SyncDelegate(delegate_pointer_type pDelegate)
    {
        Ret returnVal;

        task_pointer_type pTask = _MakeSyncTask(pDelegate, returnVal);
        
        // schedule the task
        Schedule(pTask);

        return returnVal;        
    }

    void AsynDelegate(delegate_pointer_type pDelegate)
    {
        task_pointer_type pTask = _MakeAsynTask(pDelegate);

        // schedule the task
        Schedule(pTask);

        return;
    }

    void Schedule(task_pointer_type pTask)
    {
        _Schedule(pTask);

        pTask->wait();
    }

    void SetFunctor(const functor_type& _functor)
    {
        functor_ = _functor;
    }

    const functor_type& GetFunctor()
    {
        return functor_;
    }

protected:

    virtual task_pointer_type _MakeSyncTask(delegate_pointer_type pDelegate, Ret& returnRef)
    {
        return task_pointer_type(new SyncTask<
                                 delegate_type, 
                                 acapella::synchronize::_default_::semaphore
                                 >(pDelegate, returnRef));
    }

    virtual task_pointer_type _MakeAsynTask(delegate_pointer_type pDelegate)
    {
        return task_pointer_type(new AsynTask<delegate_type>(pDelegate));
    }

    virtual void _Schedule(task_pointer_type pTask) = 0;

    functor_type functor_;
};
